/**
 * @description shop controller
 */

const Shop=require('../models/Shop')
const Product=require('../models/Product')

/**
 * 获取商店列表(热门商店)
 */

async function getHotList() {
    const list= await Shop.find().sort({_id:-1})
    return list 
}

/**
 * 获取商店信息
 * @param {String} id  //id
 */

async function getShopById(id){
    const shop=await Shop.findById(id)
    return shop
}

/**
 * 获取相应商店相关tab商品信息
 * @param {String} shopId  //商店id
 * @param {String} tab     //商品tab
 * @returns 
 */

async function getProducts(shopId,tab){
    const products=await Product.find({
        shopId,
        tabs:{
            $in:tab
        }
    }).sort({_id:-1})
    return products
}

module.exports={
    getHotList,
    getShopById,
    getProducts,
}